package com.delicious.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.delicious.dao.impl.UserDaoImpl;
import com.delicious.entity.Users;

public class LoginServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		Users user = new UserDaoImpl().checkIsAdmin(username, password);
		if(user != null){
			request.getSession().setAttribute("user", user);
			response.sendRedirect("/Delicious/admin/FoodsListServlet");
		}else{
			request.setAttribute("error", "登录权限错误");
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}
	}

}
